﻿using System;
using System.Windows.Forms;
using NanoERP.Common;
using NanoERP.Infrastructure;
using NanoERP.Model;

namespace NanoERP.BaseInfo
{
    [Module("FrmBatProductInfo")]
    public partial class FrmBatProductInfo : ModuleForm
    {
        //Goodsinfo _goodsInfo;
        //readonly GoodsinfoBLL _goodsInfoBll;
        //readonly SysdictableBLL _sysdictablebLl;
        //readonly Sysdictable _sysdictable;
        public FrmBatProductInfo()
        {
            InitializeComponent();
        }

        void FillFormInfo()
        {
            //cboGoodsUnit.DataSource = _sysdictablebLl.Query((int)SysDicEnum.基本单位);
            //cboGoodsModel.DataSource = _sysdictablebLl.Query((int)SysDicEnum.型号);
            //cboGoodsColor.DataSource = _sysdictablebLl.Query((int)SysDicEnum.颜色);
            //cboGoodsSpec.DataSource = _sysdictablebLl.Query((int)SysDicEnum.规格);
            //cboOtherUnit.DataSource = _sysdictablebLl.Query((int)SysDicEnum.其他单位);
            //cboPriceCosting.DataSource = _sysdictablebLl.Query((int)SysDicEnum.成本核算方法);
        }

        /// <summary>
        /// 绑定控件值
        /// </summary>
        void BindFormContro()
        {
            //if (_goodsInfo.GoodsDirectory != null)
            //{
            //  var obj= _sysdictablebLl.Get(_goodsInfo.GoodsDirectory.Value);
            //  txtGoodsDirectory.Text = obj == null ? "" : obj.Dicname;
            //}

            //txtGoodsName.DataBindings.Add(new Binding("Text", _goodsInfo, "GoodsName", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtGoodsPym.DataBindings.Add(new Binding("Text", _goodsInfo, "GoodsPym", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtGoodsNo.DataBindings.Add(new Binding("Text", _goodsInfo, "GoodsNo", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPackingCoef.DataBindings.Add(new Binding("Text", _goodsInfo, "PackingCoef", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtBarcode.DataBindings.Add(new Binding("Text", _goodsInfo, "Barcode", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtGoodsType.DataBindings.Add(new Binding("Tag", _goodsInfo, "GoodsType", true, DataSourceUpdateMode.OnPropertyChanged));
            //cboGoodsUnit.DataBindings.Add(new Binding("Text", _goodsInfo, "GoodsUnit", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtGoodsDirectory.DataBindings.Add(new Binding("Tag", _goodsInfo, "GoodsDirectory", true, DataSourceUpdateMode.OnPropertyChanged));
            //cboGoodsModel.DataBindings.Add(new Binding("SelectedValue", _goodsInfo, "GoodsModel", true, DataSourceUpdateMode.OnPropertyChanged));
            //cboGoodsColor.DataBindings.Add(new Binding("Text", _goodsInfo, "GoodsColor", true, DataSourceUpdateMode.OnPropertyChanged));
            //cboGoodsSpec.DataBindings.Add(new Binding("Text", _goodsInfo, "GoodsSpec", true, DataSourceUpdateMode.OnPropertyChanged));
            //diGoodsWeight.DataBindings.Add(new Binding("ValueObject", _goodsInfo, "GoodsWeight", true, DataSourceUpdateMode.OnPropertyChanged));
            //diGoodsVolume.DataBindings.Add(new Binding("ValueObject", _goodsInfo, "GoodsVolume", true, DataSourceUpdateMode.OnPropertyChanged));
            //cboOtherUnit.DataBindings.Add(new Binding("Text", _goodsInfo, "OtherUnit", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtRatio.DataBindings.Add(new Binding("Text", _goodsInfo, "Ratio", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPriceRetail.DataBindings.Add(new Binding("Text", _goodsInfo, "PriceRetail", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPriceWholesale.DataBindings.Add(new Binding("Text", _goodsInfo, "PriceWholesale", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPricePre1.DataBindings.Add(new Binding("Text", _goodsInfo, "PricePre1", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPricePre2.DataBindings.Add(new Binding("Text", _goodsInfo, "PricePre2", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPriceLow.DataBindings.Add(new Binding("Text", _goodsInfo, "PriceLow", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPriceHigh.DataBindings.Add(new Binding("Text", _goodsInfo, "PriceHigh", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPriceIn1.DataBindings.Add(new Binding("Text", _goodsInfo, "PriceIn1", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtPriceIn2.DataBindings.Add(new Binding("Text", _goodsInfo, "PriceIn2", true, DataSourceUpdateMode.OnPropertyChanged));
            //txtNote.DataBindings.Add(new Binding("Text", _goodsInfo, "Note", true, DataSourceUpdateMode.OnPropertyChanged));
            //cboPriceCosting.DataBindings.Add(new Binding("SelectedValue", _goodsInfo, "PriceCosting", true, DataSourceUpdateMode.OnPropertyChanged));

            //chIsValid.Checked = _goodsInfo.IsValid.Value.Equals(1);
            //_goodsInfo.GoodsType = _sysdictable.Id;
            //txtGoodsType.Text = _sysdictable.Dicname;
            //txtGoodsType.Tag = _sysdictable.Id;
        }

        private void toolStripAdd_Click(object sender, EventArgs e)
        {
            //_goodsInfo = new Goodsinfo();
            ControlUtil.ClearControlBind(groupPanel1);
            BindFormContro();
        }

        private void tsbSave_Click(object sender, EventArgs e)
        {
            SaveInfo();
            this.DialogResult = DialogResult.OK;
        }

        private void SaveInfo()
        {
            //_goodsInfo.IsValid = chIsValid.Checked ? (short)1 : (short)0;
            //_goodsInfoBll.Edit(_goodsInfo);

            MessageBox.Show("保存成功.", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void tsbSaveAdd_Click(object sender, EventArgs e)
        {
            SaveInfo();
            //_goodsInfo = new Goodsinfo();
            ControlUtil.ClearControlBind(groupPanel1);
            BindFormContro();
        }

        private void tsmPre_Click(object sender, EventArgs e)
        {
            //var goodsinfo = _goodsInfoBll.Get(_goodsInfo.Id - 1);

            //if (goodsinfo == null) return;
            //_goodsInfo = goodsinfo;
            //ControlUtil.ClearControlBind(groupPanel1);
            //BindFormContro();
        }

        private void tsbNext_Click(object sender, EventArgs e)
        {
            //var goodsinfo = _goodsInfoBll.Get(_goodsInfo.Id + 1);

            //if (goodsinfo == null) return;
            //_goodsInfo = goodsinfo;
            //ControlUtil.ClearControlBind(groupPanel1);
            //BindFormContro();
        }

        private void tsbExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnGoodsType_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(txtGoodsType, SysDicEnum.商品信息);
            //_goodsInfo.GoodsType = Normal.ToInt(txtGoodsType.Tag);
        }

        private void btnUnit_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(cboGoodsUnit, SysDicEnum.基本单位);
        }

        private void btnDirectory_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(txtGoodsDirectory, SysDicEnum.所属目录);
            //_goodsInfo.GoodsDirectory = Normal.ToInt(txtGoodsDirectory.Tag);
        }

        private void btnModel_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(cboGoodsModel, SysDicEnum.型号);
            //_goodsInfo.GoodsModel = Normal.ToInt(cboGoodsModel.Tag);
        }

        private void btnColor_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(cboGoodsColor, SysDicEnum.颜色);
        }

        private void btnSpec_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(cboGoodsSpec, SysDicEnum.规格);
        }

        private void btnOtherUnit_Click(object sender, EventArgs e)
        {
            CreateFormView.BindDicForm(cboOtherUnit, SysDicEnum.其他单位);
        }

        private void txtGoodsName_Leave(object sender, EventArgs e)
        {
            txtGoodsPym.Text = ChineseToSpell.GetChineseSpell(txtGoodsName.Text);
        }
    }
}
